<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出库条码列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!--            <div class="col-sm-12 search-collapse">-->
        <form id="formId">
            <div class="select-list">
                <label>出库单据：</label>
                <input type="text" style="width: 100px" name="stockoutGuid" id="stockoutGuid" onclick="$.form.reset()" oninput="entertext()"/>
                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                <a class="btn btn-primary btn-rounded btn-sm" onclick="outFP()"><i class="fa fa-search"></i>&nbsp;出库分配</a>
                <br/>
                <label>子件条码：</label>
                <input type="text" style="width: 200px" name="fbarcode" id="fbarcode" />
                <a class="btn btn-primary btn-rounded btn-sm" onclick="outSure()"><i class="fa fa-search"></i>&nbsp;确认出库</a>
                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </div>
        </form>

        <!--            </div>-->
        <div id="div1" style="height: 325px" class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
        <div id="div2" style="height: 200px" class="col-sm-8 select-table  table-striped">
            <table id="bootstrap-table2" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('outTray:outTray:edit')}]];
    var removeFlag = [[${@permission.hasPermi('outTray:outTray:remove')}]];
    var prefix = ctx + "outTray/outTray";
    $(document).ready(function () {
        document.getElementById("stockoutGuid").focus()
    });

    function entertext() {
        document.getElementById("fbarcode").focus()
    }

    // $(function() {
    var options = {
        url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        exportUrl: prefix + "/export",
        modalName: "出库条码",
        height: $("#div1").height()/1,
        showSearch: false,
        clickToSelect: true,
        singleSelect: true,
        // uniqueId:
        columns: [
            // {
            // checkbox: true
            // },
            {
                field: 'stockoutGuid',
                title: '出库单据'
            },
            {
                field: 'cargoSpaceId',
                title: '货位号'
            },
            {
                field: 'trayCode',
                title: '托盘编码'
            },
            {
                field: 'productId',
                title: '物料编码'
            },
            // {
            //     field: 'productName',
            //     title: '物料名称'
            // },
            {
                field: 'productDetailId',
                title: '子物料码'
            },
            {
                field: 'lotNo',
                title: '批次'
            },
            {
                field: 'outQuantity',
                title: '出库数量'
            }
            // ,
            // {
            //     title: '操作',
            //     align: 'center',
            //     formatter: function(value, row, index) {
            //         var actions = [];
            //         actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.stockoutGuid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
            //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.stockoutGuid + '\')"><i class="fa fa-remove"></i>删除</a>');
            //         return actions.join('');
            //     }
            // }
        ],
        //双击显示子表
        onClickRow: function (t, e) {
            options2.url = ctx + "tmsMatnr/tmsMatnr/list1?inStockId=" + t.stockoutGuid + "&matnr=" + t.productDetailId;
            $('#bootstrap-table2').bootstrapTable("refresh", options2)
        }
    };
    $.table.init(options);
    // });
    var options2 = {
        url: "",
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        // height: $("#div2").height() / 1,
        sortName: "assignNum",
        sortOrder: "desc",
        modalName: "入库单据子表",
        method: 'post',
        striped: true, //是否显示行间隔色
        pagination: true,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        singleSelect: true,
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'matnrMain',
                    title: '物料号',
                    visible: true
                },
                {
                    field: 'matnr',
                    title: '子物料号'
                },
                {
                    field: 'maktx',
                    title: '物料名称',
                    sortable: true
                },
                {
                    field: 'barcode',
                    title: '母件码',
                    sortable: true
                },
                {
                    field: 'fbarcode',
                    title: '子件码',
                    sortable: true
                },
                {
                    field: 'maktx',
                    title: '物料名称',
                    sortable: true
                },
                {
                    field: 'inStockId',
                    title: '外向交货单号',
                    sortable: true
                },
                {
                    field: 'inStockDId',
                    title: '单行号',
                    sortable: true
                },
                {
                    field: 'lotNo',
                    title: '批次',
                    sortable: true
                },

            ],
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table2').bootstrapTable("removeAll")
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    break;
            }
        },
    }
    $('#bootstrap-table2').bootstrapTable(options2)

    function outSure() {
        var fbarcode = document.getElementById("fbarcode").value;
        var stockoutGuid = document.getElementById("stockoutGuid").value;
        table.set();
        // var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        // if (rows.length == 0) {
        //     $.modal.alertWarning("请至少选择一条记录！");
        //     return;
        // }
        // $.modal.confirm("确认要手动作废选中的" + rows.length + "条作业吗?", function () {
        //     var url = table.options.handInvalidUrl;
        //     var data = {"ids": rows.join()};
        //     $.operate.submit(url, "post", "json", data);
        // });
        $.post("/pdaPk1/sureOut", {
            fbarcode: fbarcode,
            stockin_guid: stockoutGuid
        }, function (result) {
            alert(result.status)
            // location.reload();
            document.getElementById("fbarcode").value = '';
        }, "json");

    }

    function outFP() {

        var stockoutGuid = document.getElementById("stockoutGuid").value;
        if (stockoutGuid == "") {
            alert("请选择要分配的交货单号");
            return
        }
        // table.set();
        // var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        // if (rows.length == 0) {
        //     $.modal.alertWarning("请至少选择一条记录！");
        //     return;
        // }
        // $.modal.confirm("确认要手动作废选中的" + rows.length + "条作业吗?", function () {
        //     var url = table.options.handInvalidUrl;
        //     var data = {"ids": rows.join()};
        //     $.operate.submit(url, "post", "json", data);
        // });
        $.post("/pdaPk1/autoAllocation", {
            stockin_guid: stockoutGuid
        }, function (result) {
            alert(result.errorInfo)
            // location.reload();
            document.getElementById("fbarcode").value = '';
        }, "json");

    }
</script>
</body>
</html>